/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.sdt.refinement;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.yonsei.iwb.sdt.datastructure.TargetInstance;
import java.util.Vector;
import edu.yonsei.iwb.sdt.ontology.PropertyArc;

/**
 *
 * @author JDK
 */
public class QualifiedConjunctionRefinement extends Refinement {

    private String name = new String();
    private ExpandingHistory eh;
    private String corename = new String();
    
    public QualifiedConjunctionRefinement(String name, String corename, ExpandingHistory eh) {
        this.name = name;
        this.eh = eh;
        this.corename = corename;
    }
    
    public QualifiedConjunctionRefinement(String prefix, ExpandingHistory eh, String bestdc, String newdc) {
        this.eh = eh;
        Vector<String> quantifiers = this.eh.getQuantifierSet();
        Vector<PropertyArc> propertySet = this.eh.getPropertySet();
//        this.standardClass = r;
//        bestdc.replace("(", "((");
//        bestdc.replace(")", "");
        this.name = bestdc + DLConstructors.CONJUNCTION +"("+ newdc+")";
        this.corename = bestdc + DLConstructors.CONJUNCTION +"("+ newdc+")";
        
        for (int i =0 ; i < propertySet.size(); i++) {
            PropertyArc pa = propertySet.get(i);
            String p = pa.getProperty();
            String q = quantifiers.get(i);
            if(pa.getDirection()){
                this.name = q+" "+p+".("+this.name+")";                
            }else{
                this.name = q+" "+p+"￣.("+this.name+")";                
            }
        }
        
        this.name = prefix + this.name;
    }
           
    public ExpandingHistory getExpandingHistory(){
        return this.eh;
    }

    @Override
    public void generateRefinementName() {
        super.refinement_name = this.name;
    }
    
    @Override
    public Refinement generateUpdatedRefinement(Vector<TargetInstance> instanceSet){
        Refinement ref = new QualifiedConjunctionRefinement(this.name, this.corename, this.eh);
        ref.setBranchingType(this.branching_type);
        ref.setConstraintConstructor(this.cc);
        Vector<TargetInstance> oldinsSet = this.getInstanceSet();
        for (int i = 0; i < instanceSet.size(); i++) {
            TargetInstance r = instanceSet.get(i);
            if(oldinsSet.contains(r)){
                ref.setInstanceSet(r);
            }
        }
//        private boolean refinement_type = true;
//        protected String refinement_name;
//        private Vector<Resource> instanceSet;
        return ref;
    }
    
    @Override
    public String getCoreName() {
        return this.corename;
    }

    @Override
    public Vector<Resource> getConstraintMatcherInstance(Model model) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String getName() {
        return this.name;
    }
}
